//
//  BusinessManageViewController.m
//  AnXin100
//
//  Created by Sakura on 2018/11/7.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "BusinessManageViewController.h"
#import "UINavigationBar+LXTransparency.h"
#import "ZXSampleStarAppraiseView.h"
#import "BusinessManageTableViewCell.h"
@interface BusinessManageViewController ()<UITableViewDelegate, UITableViewDataSource>
{
    UIImageView *_headImageView;
}
@property (nonatomic) UINavigationBar *navigationBar;
@property (nonatomic, strong) UITableView *mainTable;
@property (nonatomic, strong) UIView *tableHeaderView;
@property (nonatomic, strong) UIImageView *storeIconImage;
@property (nonatomic, strong) UILabel *storeNameLabel;
@property (nonatomic, strong) UIButton *messageBtn;
@property (nonatomic, strong) UIView *firstDataView;
@property (nonatomic, strong) ZXSampleStarAppraiseView *starView;

@end

@implementation BusinessManageViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    // 也可以手动设置 alpha
    [self.navigationBar lx_setAlpha:self.navigationBar.lx_lastSetAlpha];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    // 跳转界面时可根据需要还原 alpha
    [self.navigationBar lx_resetAlpha];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.mainTable];
    _mainTable.tableHeaderView = self.tableHeaderView;
    //    self.navigationController.navigationBar.hidden = YES;
    self.navigationBar = self.navigationController.navigationBar;
    // 关联 scroll view 就可以自动调整 alpha
    [self.navigationBar lx_setScrollView:self.mainTable];
    [self.navigationBar lx_setFullyTransparentOffset:CGRectGetHeight(self.mainTable.tableHeaderView.bounds) - CGRectGetMaxY(self.navigationBar.frame)];
    self.navigationItem.title = @"店铺管理";
    [PublicMonMethods setupNavigationItems:self];
}


- (UITableView *)mainTable {
    if (!_mainTable) {
        _mainTable = [[UITableView alloc] initWithFrame:CGRectMake(0, -Hn, SCREEN_WIDTH, SCREEN_HEIGHT + Hn) style:UITableViewStylePlain];
        _mainTable.delegate = self;
        _mainTable.dataSource = self;
        [_mainTable registerClass:[BusinessManageTableViewCell class] forCellReuseIdentifier:@"BusinessManageTableViewCell"];
        _mainTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _mainTable;
}

- (UIView *)tableHeaderView {
    if (!_tableHeaderView) {
        _tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 450)];
        _tableHeaderView.backgroundColor = [UIColor whiteColor];
        
        _headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 230)];
        _headImageView.image = [UIImage imageNamed:@"GD.jpg"];
        [_tableHeaderView addSubview:_headImageView];
        
        _storeIconImage = [[UIImageView alloc] initWithFrame:CGRectMake(15, Hn + 10, 50, 50)];
        _storeIconImage.layer.cornerRadius = 25;
        _storeIconImage.layer.masksToBounds = YES;
        _storeIconImage.image = [UIImage imageNamed:@"GD.jpg"];
        [_headImageView addSubview:_storeIconImage];
        
        _storeNameLabel = [UILabel getCustomLabel:[UIColor colorWithHex:0x333333] font:[UIFont systemFontOfSize:16] rect:CGRectMake(CGRectGetMaxX(_storeIconImage.frame) + 10, _storeIconImage.mj_y, SCREEN_WIDTH / 2, 25)];
        _storeNameLabel.text = @"哆啦A梦";
        [_headImageView addSubview:_storeNameLabel];
        
        _starView = [[ZXSampleStarAppraiseView alloc] initWithFrame:CGRectMake(_storeNameLabel.mj_x, CGRectGetMaxY(_storeNameLabel.frame), 80, 15)];
        _starView.score = 5;
        [_headImageView addSubview:_starView];
        
        _firstDataView = [[UIView alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(_storeIconImage.frame) + 15, SCREEN_WIDTH - 40, 75)];
        _firstDataView.backgroundColor = [UIColor whiteColor];
        _firstDataView.layer.cornerRadius = 10;
        _firstDataView.layer.masksToBounds = YES;
        [_tableHeaderView addSubview:_firstDataView];
        
        NSArray *firstDataArray = @[@"十万+\n客户量", @"85.98%\n回头率", @"10万+\n收藏量", @"2000.00\n销售额"];
        for (NSInteger i = 0; i < firstDataArray.count; i++) {
            UILabel *dataLabel = [[UILabel alloc] initWithFrame:CGRectMake(_firstDataView.mj_w / 4 * i, 0, _firstDataView.mj_w / 4, _firstDataView.mj_h)];
            dataLabel.font = [UIFont systemFontOfSize:14];
            dataLabel.textColor = [UIColor colorWithHex:0x999999];
            dataLabel.textAlignment = NSTextAlignmentCenter;
            dataLabel.numberOfLines = 2;
            dataLabel.text = firstDataArray[i];
            
            NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc]initWithString:firstDataArray[i]];
            NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
            paragraphStyle.paragraphSpacing = 10;       //行间距是20
            paragraphStyle.alignment = NSTextAlignmentCenter;   //对齐方式为居中对齐
            [attributeStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [firstDataArray[i] length])];
            dataLabel.attributedText = attributeStr;
            [_firstDataView addSubview:dataLabel];
        }
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(_firstDataView.frame) + 25, SCREEN_WIDTH - 40, 75)];
        imageView.image = [UIImage imageNamed:@"businessBack"];
        [_tableHeaderView addSubview:imageView];
        
        UILabel *currenMonthLabel = [UILabel getCustomLabel:[UIColor blackColor] font:[UIFont systemFontOfSize:16] rect:CGRectMake(0, CGRectGetMaxY(imageView.frame) + 20, SCREEN_WIDTH, 20)];
        currenMonthLabel.text = @"本月数据";
        currenMonthLabel.textAlignment = NSTextAlignmentCenter;
        [_tableHeaderView addSubview:currenMonthLabel];
        
        NSArray *secondDataArray = @[@"访客数（个）\n600 ↑5%", @"销量（件）\n600 ↑5%", @"成交额（元）\n6000.00 ↑5%"];
        for (NSInteger i = 0; i < secondDataArray.count; i++) {
            UILabel *dataLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 3 * i, CGRectGetMaxY(currenMonthLabel.frame) + 20, SCREEN_WIDTH / 3, _firstDataView.mj_h)];
            dataLabel.font = [UIFont systemFontOfSize:14];
            dataLabel.textColor = [UIColor colorWithHex:0x999999];
            dataLabel.textAlignment = NSTextAlignmentCenter;
            dataLabel.numberOfLines = 2;
            dataLabel.text = secondDataArray[i];
            
            NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc]initWithString:secondDataArray[i]];
            NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
            paragraphStyle.paragraphSpacing = 10;       //行间距是20
            paragraphStyle.alignment = NSTextAlignmentCenter;   //对齐方式为居中对齐
            [attributeStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [secondDataArray[i] length])];
            dataLabel.attributedText = attributeStr;
            [_tableHeaderView addSubview:dataLabel];
        }
    }
    return _tableHeaderView;
}

#pragma mark - UITableView Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 150;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    BusinessManageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BusinessManageTableViewCell"];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 40;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
    view.backgroundColor = COLOR_LINE;
    
    return view;
}



@end
